<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="/css/pintuer.css">
    <link rel="stylesheet" href="/css/admin.css">
    <script src="/js/jquery.js"></script>
    <script src="/js/pintuer.js"></script>
    <script src="/js/vuejs-2.5.16.js"></script>
    <script src="/js/axios-0.18.0.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="/element-ui/lib/index.js"></script>


</head>
<body>
<div class="panel admin-panel" id="papersListDiv">
    <div class="panel-head"><strong class="icon-reorder"> 试卷列表</strong> <a href="" style="float:right; display:none;">添加字段</a>
    </div>
    <div class="padding border-bottom">
        <form>
            <ul class="search" style="padding-left:10px;">
                <li><a class="button border-main icon-plus-square-o" href="/paper_add.html" > 添加选项</a></li>
            </ul>
        </form>
    </div>
    <table class="table table-hover text-center">
        <tr>
            <th width="5%">序号</th>
            <th>问卷名称</th>
            <th>问卷封面</th>
            <th>问卷水平</th>
            <th>问卷星级</th>
            <th width="310">操作</th>
        </tr>

        <tr v-for="(paper,index) in pageResult.items">
            <td style="text-align:left; padding-left:20px;">{{index+1}}</td>
            <td>{{paper.name}}</td>
            <td width="10%"><img :src="paper.cover" alt="" width="70" height="50"/></td>
            <td>{{paper.level}}</td>
            <td>{{paper.star}}</td>
            <td>
                <div class="button-group">
                    <a class="button border-main" :href="'/paper.html?id='+paper.id"><span class="icon-edit"></span>查看试卷内容</a>
                    <a class="button border-main" :href="'/paper_add.html?id='+paper.id"><span class="icon-edit"></span>修改</a>
                    <a class="button border-red" href="javascript:void(0)" @click="deletePaperByid(paper.id)">
                        <span class="icon-trash-o"></span> 删除</a>
                </div>
            </td>
        </tr>


    </table>
    <div position="fixed">
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageResult.page"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="pageResult.pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageResult.counts">
        </el-pagination>
    </div>

</div>

<script type="text/javascript">
    const app = new Vue({
        el: '#papersListDiv',
        data: {
            page:1,
            pageSize:10,
            pageResult:{}
        },
        methods: {
            findAllPaper(){
                axios.get("/soul/paper/findPaperByPage",{params:{
                        page: this.page,
                        pageSize: this.pageSize
                    }}).then(resp=>{

                    this.pageResult=resp.data;
                    console.log(this.pageResult.list)

                })
            },

            handleCurrentChange(val) {
                this.page=val;
                this.findAllPaper();
                console.log(`当前页: ${val}`);
            },
            handleSizeChange(val) {
                this.pageSize=val;
                this.findAllPaper();
                console.log(`每页 ${val} 条`);
            },
            deletePaperByid(id){
                if (confirm("是否确认删除")) {
                    let paperId=id.toString()
                    axios.delete("/soul/paper/delete?id="+paperId).then(resp=>{

                        if (resp.data) {
                            location.href="/paper_list.html"
                        }else {
                            alert("删除失败")
                        }
                    })
                }
            }
        },
        created(){
            this.findAllPaper();
        }
    })
</script>
<!-- <script src="/js/verify.js"></script>-->
</body>
</html>